package com.controller.admin.job;

import com.alibaba.fastjson.JSONObject;
import com.dao.JobDao;
import com.dao.UserDao;
import com.dao.imp.JobDaoimpl;
import com.dao.imp.UserDaoimpl;
import com.entity.Vo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/SelectAllJobServlet")
public class SelectAllJobServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
//        UserDao userDao  = new UserDaoimpl();
        JobDao jobDao = new JobDaoimpl();
        List<Object> list = null;
        try {
            list=jobDao.selectJobList(req, resp);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        HttpSession session = req.getSession();
        session.setAttribute("job", list);
        Vo vo = new Vo();
        vo.setCode(0);
        vo.setMsg("success");
        try {
            int i = jobDao.countJob(req, resp);
            System.out.println("jobi = " + i);
            vo.setCount(i);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        vo.setData(list);
        //list集合用json转到前端
        resp.getWriter().write(JSONObject.toJSON(vo).toString());
    }
}
